<?php
/// Copyright (c) 2004-2008, Cain Chen / Hina :: 工程幼稚園
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)
/// i18n modified by hina, http://hina.ushiisland.net/blog/hinablue
/// The functions modified from TextCube Source Code
class pluginLang {
	function plts($t) {
		global $__ts;
		if (isset($__ts[$t])) {
			return $__ts[$t];
		} else {
			return $t;
		}
	}
	function plfs($t) {
		$t = pluginLang::plts($t);
		if (func_num_args() <= 1) {
			return $t;
		} else {
			for ($i = 1; $i < func_num_args(); $i++) {
				$arg = func_get_arg($i);
				$t = str_replace('%' . $i, $arg, $t);
			}
			return $t;
		}
	}
	function pllang2javascript() {
		global $__ts;
		
		ob_start();
		echo <<<EOT
		<script language="javascript" type="text/javascript">
		//<![CDDA[
		/* PHP to javascript */
		function is_array( mixed_var ) {
		    // http://kevin.vanzonneveld.net
		    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		    // +   improved by: Legaev Andrey
		    // +   bugfixed by: Cord
		 
		    return ( mixed_var instanceof Array );
		}
		function str_replace(search, replace, subject) {
		    // http://kevin.vanzonneveld.net
		    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		    // +   improved by: Gabriel Paderni
		    // +   improved by: Philip Peterson
		    // +   improved by: Simon Willison (http://simonwillison.net)
		    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
		    // -    depends on: is_array
		    
		    var f = search, r = replace, s = subject;
		    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
		 
		    while(j = 0, i--){
		        while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f);
		    }
		     
		    return sa ? s : s[0];
		}

		function _plts(msg) {

EOT;
		echo "__plugin_text = {\n";
		foreach ($__ts as $key => $value) {
			$key = str_replace("\n", "\\n", addslashes($key));
			$value = str_replace("\n", "\\n", addslashes($value));
			echo "\t'$key': '$value',\n";
		}

		echo <<<EOT
			'': '' // dummy
			};
			if (__plugin_text[msg]!=undefined) {
				var msg = str_replace('\\\\n', '\\n', __plugin_text[msg]);
			}
			return msg;
		}

		//]>
		</script>
EOT;
		$javascript = ob_get_contents();
		ob_clean();
		flush();
		
		return ($javascript);
	}
}
?>